﻿<%@ WebHandler Language="C#" Class="ShowDetailContract" %>

using System;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business;
using Chenxin.Lib.Business.BLL;
public class ShowDetailContract : AjaxHandlerBase
{
    //*******************************************
    //功能概要       ：基本权限初始化设定
    //参数説明       ： 
    //返回值説明     ：-
    //功能詳細       ：-
    //作成者         ：chen.yugong 
    //作成日         ：2010-06-29
    //修改者         ：
    //修改日         ：2010-07-13
    //*******************************************
    
    public ShowDetailContract()
    {
    }

    //*******************************************
    //功能概要       ：请求处理
    //参数説明       ：context 请求上下文
    //返回值説明     ：-
    //功能詳細       ：根据请求名 分发请求
    //作成者         ：chen.yugong 
    //作成日         ：2010-06-29
    //修改者         ：
    //修改日         ：2010-07-13
    //*******************************************
    override public void RequestProcess(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        string strOp = context.Request["op"];
        string strResponse = "";
        string FilePath = Constants.FilePath_Contract;
        
        switch (strOp.ToLower())
        {
            case "getmodel":
                strResponse = getModel(context);
                break;
            default:
                break;
        }
        context.Response.Write(strResponse);
    }

  
     //*******************************************
     //功能概要       ：获得详细信息
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获得详细信息
     //作成者         ：chen.yugong 
     //作成日         ：2010-06-29
     //修改者         ：
     //修改日         ：
     //*******************************************
     public string getModel(HttpContext context)
     {
         try
         {
             string RecordId = context.Request["id"];
             Chenxin.Lib.Business.Entity.t_Contract_BaseInfo info = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(RecordId));
             if (info == null) {
                 return string.Format("{{success:'1',msg:'{0}',data:''}}", Resources.Message.Msg_Search_NoData);
             }
             Chenxin.Lib.Business.Entity.t_Contract_Infomation info1 = Chenxin.Lib.Business.DAL.t_Contract_Infomation.GetModel(new Guid(RecordId));
         
             Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo cci = Chenxin.Lib.Business.DAL.t_Contract_CommisionInfo.GetModel(info.ContractId);

             Chenxin.Lib.Business.Entity.t_Contract_Infomation1 info5 = Chenxin.Lib.Business.DAL.t_Contract_Infomation1.GetModel(new Guid(RecordId));

             Chenxin.Lib.Business.Entity.ContractLackItemsInfo info6 = Chenxin.Lib.Business.DAL.ContractLackItemsInfo.GetModel(new Guid(RecordId));
             Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo3 tp3 = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo3.GetModelByContractId(info.ContractId);
             List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo1> list1 = new List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo1>();
             List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> list2 = new List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2>();
             if (tp3 != null)
             {
                 list1 = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo1.GetListArray(string.Format(" MainId = '{0}' ", tp3.MainId));
                 list2 = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetListArray(string.Format(" MainId = '{0}' ", tp3.MainId));
             }
             StringBuilder sb =new StringBuilder();
             
           //  sb.Append("<ul class=\"clu_box\">");
             sb.Append("<div class=\"padding10\">");
             if (tp3 != null)
             {
                
                 sb.AppendFormat("<li class=\"width50\"><b> 原主贷人：</b><span class=\"red20\">{0}</span></li>", tp3.SaleName);
                 sb.AppendFormat("<li class=\"width50\"><b> 身份证号：</b><span class=\"red20\">{0}</span></li>", tp3.SaleIDCard);

                 for (int i = 0; i < list2.Count; i++)
                 {
                     Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2 tps = list2[i];
                     sb.AppendFormat("<li class=\"width50\"><b> 原共有人：</b><span class=\"red20\">{0}</span></li>", tps.SaleNamePublic);
                     sb.AppendFormat("<li class=\"width50\"><b> 身份证号：</b><span class=\"red20\">{0}</span></li>", tps.SaleIDCardPublic);
                 }
                 sb.AppendFormat("<li class=\"width50\"><b> 电话号码：</b><span class=\"red20\">{0}</span></li>", tp3.SalerPhone);
                 sb.AppendFormat("<li class=\"width50\"><b> 原贷款银行：</b><span class=\"red20\">{0}</span></li>", tp3.OldLoanBank);
                 sb.AppendFormat("<li class=\"width50\"><b> 原贷款金额：</b><span class=\"red20\">{0}</span></li>", tp3.OldLoanMoney);
                 sb.AppendFormat("<li class=\"width50\"><b> 剩余贷款金额：</b><span class=\"red20\">{0}</span></li>", tp3.OldRestMoney);
                 sb.AppendFormat("<li class=\"width50\"><b> 结算日期：</b><span class=\"red20\">{0}</span></li>", tp3.LoanComplete);
                 sb.AppendFormat("<li class=\"width50\"><b> 抵押注销日期：</b><span class=\"red20\">{0}</span></li>", tp3.MortgageClearDate);
                
                
                 for (int i = 0; i < list1.Count; i++)
                 {
                     Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo1 tps = list1[i];
                     if (tps.BOwner)
                     {
                         sb.AppendFormat("<li class=\"width50\"><b> 主贷人：</b><span class=\"bluef20\">{0}</span></li>", tps.CustomerName);
                         sb.AppendFormat("<li class=\"width50\"><b> 身份证号：</b><span class=\"bluef20\">{0}</span></li>", tps.IDNum);
                     }
                     else
                     {
                         sb.AppendFormat("<li class=\"width50\"><b> 共有人：</b><span class=\"bluef20\">{0}</span></li>", tps.CustomerName);
                         sb.AppendFormat("<li class=\"width50\"><b> 身份证号：</b><span class=\"bluef20\">{0}</span></li>", tps.IDNum);
                     }
                 }
                 sb.AppendFormat("<li class=\"width50\"><b> 电话号码：</b><span class=\"bluef20\">{0}</span></li>", tp3.BuyerPhone);
                 sb.AppendFormat("<li class=\"width50\"><b> 贷款办理渠道：</b><span class=\"bluef20\">{0}</span></li>", tp3.LoanDealMode);
                 sb.AppendFormat("<li class=\"width50\"><b> 贷款种类：</b><span class=\"bluef20\">{0}</span></li>", tp3.LoanInfo);
                 sb.AppendFormat("<li class=\"width50\"><b> 受理银行：</b><span class=\"bluef20\">{0}</span></li>", tp3.ReceiveBank);
                 sb.AppendFormat("<li class=\"width50\"><b> 商业贷款金额：</b><span class=\"bluef20\">{0}</span></li>", tp3.SYMoney);
                 sb.AppendFormat("<li class=\"width50\"><b> 年限：</b><span class=\"bluef20\">{0}</span></li>", tp3.SYYear);
                 sb.AppendFormat("<li class=\"width50\"><b> 公积金贷款金额：</b><span class=\"bluef20\">{0}</span></li>", tp3.GJJmoney);
                 sb.AppendFormat("<li class=\"width50\"><b> 年限：</b><span class=\"bluef20\">{0}</span></li>", tp3.GJJyear);
                 sb.AppendFormat("<li class=\"width50\"><b> 评估费：</b><span class=\"bluef20\">{0}</span></li>", tp3.EvaluateFee);
                 sb.AppendFormat("<li class=\"width50\"><b> 保险费：</b><span class=\"bluef20\">{0}</span></li>", tp3.InsuranceFee);
                 sb.AppendFormat("<li class=\"width50\"><b> 收件收据放款担保费：</b><span class=\"bluef20\">{0}</span></li>", tp3.OutVouchFee);
                 sb.AppendFormat("<li class=\"width50\"><b> 转按揭担保费：</b><span class=\"bluef20\">{0}</span></li>", tp3.VouchFee);
                 sb.AppendFormat("<li class=\"width50\"><b> 贷款合同签订日：</b><span class=\"bluef20\">{0}</span></li>", tp3.LoanContractDate);
                 sb.AppendFormat("<li class=\"width50\"><b> 贷款合同送银行日：</b><span class=\"bluef20\">{0}</span></li>", tp3.BankLoanDate);
                 sb.AppendFormat("<li class=\"width50\"><b> 贷款合同回公司日：</b><span class=\"bluef20\">{0}</span></li>", tp3.ReceiveLoanDate);
                 sb.AppendFormat("<li class=\"width50\"><b> 收件收据送银行日：</b><span class=\"bluef20\">{0}</span></li>", tp3.VoucherToBankDate);
                 sb.AppendFormat("<li class=\"width50\"><b> 抵押证送银行日：</b><span class=\"bluef20\">{0}</span></li>", tp3.CertificateDate);
                 sb.AppendFormat("<li class=\"width50\"><b> 银行放款日：</b><span class=\"bluef20\">{0}</span></li>", tp3.BankCompleteDate);
                 sb.AppendFormat("<li class=\"width50\"><b> 发放月份：</b><span class=\"bluef20\">{0}</span></li>", tp3.BankCompleteDate);
                 sb.Append("</div>");
             }
            // sb.Append("</ul>");
            // sb.Append("</div>");
             return string.Format("{{success:'1',msg:'成功',data:{{model:{0},model1:{1},model3:{2},model4:{3},info:'{4}',model5:{5},model6:{6}}}}}", Chenxin.Lib.Utility.JsonHelp.Convert2Json(info), Chenxin.Lib.Utility.JsonHelp.Convert2Json(info1), Chenxin.Lib.Utility.JsonHelp.Convert2Json(tp3), Chenxin.Lib.Utility.JsonHelp.Convert2Json(cci), sb.ToString(), Chenxin.Lib.Utility.JsonHelp.Convert2Json(info5), Chenxin.Lib.Utility.JsonHelp.Convert2Json(info6));
         }
         catch (Exception ex)
         {
             return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
         }
     }
    
     //*******************************************
     //功能概要       ：响应字符串
     //参数説明       ：strMsg 消息 
     //返回值説明     ：void
     //功能詳細       ：权限检查
     //作成者         ：chen.yugong 
     //作成日         ：2010-07-01
     //修改者         ：
     //修改日         ：2010-07-13
     //*******************************************
     public override bool CustomerCheckPermint(HttpContext context, out string strMsg)
     {
         if (context.Request["op"] != null)
         {
             string op = context.Request["op"].ToLower();
             //实体变量
             Chenxin.Lib.Business.Entity.ContractApplyInfo model = null;
             //传递参数用
             System.Collections.Hashtable per = new System.Collections.Hashtable();
             System.Collections.Hashtable confine = new System.Collections.Hashtable();
             string modelid = string.Empty;
             if (op.Equals("checkpermit") && ("edit".Equals(context.Request["code"].ToLower()) || "confirm".Equals(context.Request["code"].ToLower())))
             {
                 modelid = context.Request["modelid"];

                 //判断op参数
                 if ("edit".Equals(context.Request["code"].ToLower()))
                 {
                     if (string.IsNullOrEmpty(modelid))
                     {
                         strMsg = retExecResult(Constants.ExecResult.Error, "标识丢失，获取信息失败！", "");
                         return false;
                     }
                     model = Chenxin.Lib.Business.DAL.ContractApplyInfo.GetModel(new Guid(modelid));
                     if (model == null)
                     {
                         strMsg = retExecResult(Constants.ExecResult.Error, "数据不存在，获取信息失败！", "");
                         return false;
                     }
                     //加如权限项
                     per.Add("ALL", Constants.Permit_EditContractApplyInfo_All);
                     per.Add("CITY", Constants.Permit_EditContractApplyInfo_City);
                     per.Add("COMPANY", Constants.Permit_EditContractApplyInfo_Company);
                     per.Add("DEPART", Constants.Permit_EditContractApplyInfo_Department);
                     //加入范围
                     confine.Add("CityId", model.CreateCityId);
                     confine.Add("CompanyId", model.CreateCompanyId);
                     confine.Add("OperatorId", model.CreateUserId);
                     //检查权限
                     return CheckPermint(per, confine, checkDepartPermit(model.CreateDepartmentId, context.Request["code"].ToLower()), out strMsg);
                 }
             }
         }
         strMsg = "{success:1,msg:'',data:{permit:true}}";
         return true;
     }

     //*******************************************
     //功能概要       ：部门内有无封盘解盘权限
     //参数説明       ：context 上下文
     //返回值説明     ：bool
     //功能詳細       ：部门内有无封盘解盘权限
     //作成者         ：chen.yugong 
     //作成日         ：2010-07-01
     //修改者         ：
     //修改日         ：2010-07-13
     //*******************************************
     public bool checkDepartPermit(Guid departId, string op)
     {
         //检查有无权限
         System.Text.StringBuilder sb = new System.Text.StringBuilder();
         sb.AppendFormat(" (Departid = '{0}' AND  Userid= '{1}') ", departId, CurrentUserInfo.UserId);
         System.Collections.Generic.List<Chenxin.Lib.Business.Entity.t_Business_EmpSetting> list = Chenxin.Lib.Business.DAL.t_Business_EmpSetting.GetListArray(sb.ToString());
         if (list.Count > 0)
         {
             Chenxin.Lib.Business.Entity.t_Business_EmpSetting hrp = list[0];
             //修改业绩申请
             if ("edit".Equals(op))
             {
                 return hrp.EditContractApply;
             }
         }
         return false;
     }
}